from app import db
from datetime import datetime

class RolePermission(db.Model):
    """角色权限关联表"""
    __tablename__ = 'role_permissions'
    
    id = db.Column(db.Integer, primary_key=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'), nullable=False)
    permission_id = db.Column(db.Integer, db.ForeignKey('permissions.id'), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    
    # 唯一约束
    __table_args__ = (db.UniqueConstraint('role_id', 'permission_id', name='uq_role_permission'),)
    
    def __repr__(self):
        return f'<RolePermission {self.role_id}:{self.permission_id}>' 